/*
ID: guoxu1
PROG: gift1
LANG: C++
*/
#include <fstream>
#include <vector>
#include <map>
using namespace std;

#define cin fin
#define cout fout

int main()
{
	ifstream fin( "gift1.in" );
	ofstream fout( "gift1.out" );

	map<string, int> data;
	vector<string> dict;

	int count = 0;
	cin >> count;
	for( int i = 0; i < count; i++ )
	{
		string s;
		cin >> s;
		data[s] = 0;
		dict.push_back(s);
	}
	for( int i = 0; i < count; i++ )
	{
		string s;
		cin >> s;
		int amount = 0, n = 0;
		cin >> amount >> n;
		if( n == 0 ) continue;
		data[s] = data[s] - ( amount - amount % n );
		for( int j = 0; j < n; j++ )
		{
			string s;
			cin >> s;
			data[s] = data[s] + amount / n;
		}
	}
	for( vector<string>::iterator it = dict.begin(); it != dict.end(); it++ )
	{
		cout << *it << " " << data[ *it ] << endl;
	}
	return 0;
}
